// 订阅先引入store
import store from "../redux";
import { useEffect } from "react";
import { useState } from "react";
import { getCartActions } from "../redux/action/getCartAction";
export default function Home() {
  let [num, setNum] = useState(0);
  useEffect(() => {
    if (store.getState().cartReducer.cartList.length === 0) {
      store.dispatch(getCartActions());
    } else {
      setNum(store.getState().cartReducer.cartList.length);
    }
  });
  store.subscribe(() => {
    setNum(store.getState().cartReducer.cartList.length);
  });
  return (
    <div>
      Home
      <h1>购物车数量：{num}</h1>
    </div>
  );
}
